package org.xtframe.dao;

import java.util.ArrayList;

import org.xtframe.entity.DataBase;
import org.xtframe.entity.ServerData;
import org.xtframe.util.ContextUtil;
import org.xtframe.util.SpringUtil;

public class DataBaseFactory {

	public static DataBaseDao getDataBaseDaoForJndiName(String jndiName){
		return (DataBaseDao) SpringUtil.getBean(jndiName);
	}
	
	public static DataBaseDao getDataBaseDaoForSqlId(String sqlId){
		ServerData serverData = ContextUtil.getServerData();
		ArrayList<DataBase> dataBase = serverData.getDataBase();
		for(DataBase db : dataBase){
			if(db.isInSQL(sqlId)) return getDataBaseDaoForJndiName(db.getJndiName());
		}
		return getDataBaseDaoForJndiName("dataBaseDao");
	}
}
